include('shared.lua')

local PlayerViewAngles = Angle(0,0,0)
local CamAngle = Angle(60,90,0)
local Fdir = 1
local Sdir = 1
local SStep = 1

function spraylogo()
	
	return angles
end
function GM:CalcView( ply, origin, angles, fov )
	local view = {}
	if !self.MapVoteMode then
		CamAngle = ply:GetNWAngle("ViewAngles")
		//local viewtrace = {}
		//	viewtrace.start = origin 
		//	viewtrace.endpos = 
		//	viewtrace.filter = ply
		//local trace = util.TraceLine(viewtrace)
		//view.origin = origin + (Vector(0,CamAngle.p,CamAngle.y):Normalize() * Vector(1,-1,1) * 500 * trace.Fraction)
		view.origin = origin + (Vector(0,CamAngle.p,CamAngle.y):Normalize() * Vector(1,-1,1) * 500)
		view.angles = CamAngle
	end
	return view
end

function GM:CreateMove(cmd)
	if !self.MapVoteMode then
		if cmd:GetForwardMove() != 0 then
			if SStep != 1 then
				SStep = 1
			end
			if cmd:GetForwardMove() < 0 then
				PlayerViewAngles = Angle(0,270,0)
				Fdir = -1
			else
				PlayerViewAngles = Angle(0,90,0)
				Fdir = 1
			end
		else
			Fdir = 0
		end
		if cmd:GetSideMove() != 0 then
			if SStep != 2 then
				SStep = 2
			end
			if cmd:GetSideMove() < 0 then
				PlayerViewAngles = Angle(0,180,0)
				Sdir = -1
			else
				PlayerViewAngles = Angle(0,0,0)
				Sdir = 1
			end
		else
			Sdir = 0
		end
		if SStep != 0 then
			if cmd:GetSideMove() == 0 then
				if cmd:GetForwardMove() == 0 then
					SStep = 0
				end
			end
		end
		cmd:SetViewAngles(PlayerViewAngles)
		if SStep == 1 then
			cmd:SetForwardMove( cmd:GetForwardMove() * Fdir )
			if Fdir > 0 then
				cmd:SetSideMove( cmd:GetSideMove() * Sdir )
			else
				cmd:SetSideMove( cmd:GetSideMove() * Sdir * (-1))
			end
		elseif SStep == 2 then
			cmd:SetForwardMove( cmd:GetSideMove() * Sdir )
			if Sdir < 0 then
				cmd:SetSideMove( cmd:GetForwardMove() * Fdir )
			else
				cmd:SetSideMove( cmd:GetForwardMove() * Fdir * (-1) )
			end
		end
		
		/*
		cmd:SetUpMove(cmd:GetUpMove())
		cmd:SetSideMove(0)
		local MPos = Vector(gui.MouseX(),gui.MouseY(),0)
		*/
		
		
	end
end

function GM:PostPlayerDraw(ply)
	if PlayerViewAngles == Angle(0,270,0) then
		ply:SetModelScale(Vector(0.01,1,1))
	elseif PlayerViewAngles == Angle(0,90,0) then
		ply:SetModelScale(Vector(0.01,1,1))
	else
		ply:SetModelScale(Vector(1,0.01,1))
	end
end

function GM:ShowGamemodeChooser()
	if (!self.MapVoteMode) then	
		self.MapVoteMode = true
//		surface.PlaySound("ZeldaMaloMart.wav")
	end
	self:ScoreboardHide()
	self.BaseClass:ShowGamemodeChooser(self)	
end
